package com.ruoyi.edge.rule.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.mybatis.core.page.PageQuery;
import com.ruoyi.common.mybatis.core.page.TableDataInfo;
import com.ruoyi.edge.rule.domain.RuleConfig;
import com.ruoyi.edge.rule.mapper.RuleConfigMapper;
import com.ruoyi.edge.rule.service.RuleConfigService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * 计算规则配置信息
 */
@Slf4j
@RequiredArgsConstructor
@Service
public class RuleConfigServiceImpl implements RuleConfigService {

    private final RuleConfigMapper ruleConfigMapper;

    @Override
    public TableDataInfo<RuleConfig> listPage(RuleConfig ruleConfig, PageQuery pageQuery) {

        LambdaQueryWrapper<RuleConfig> lqw = new LambdaQueryWrapper<>();
        Page<RuleConfig> page = ruleConfigMapper.selectPage(pageQuery.build(), lqw);
        return TableDataInfo.build(page);
    }

    @Override
    public R<RuleConfig> get(String id) {
        RuleConfig ruleConfig = ruleConfigMapper.selectById(id);
        return R.ok(ruleConfig);
    }

    @Override
    public R<String> add(RuleConfig ruleConfig) {
        ruleConfigMapper.insert(ruleConfig);
        return R.ok("新增成功");
    }

    @Override
    public R<String> edit(RuleConfig ruleConfig) {
        ruleConfigMapper.updateById(ruleConfig);
        return R.ok("修改成功");
    }

    @Override
    public R<String> remove(String id) {
        ruleConfigMapper.deleteById(id);
        return R.ok("删除成功");
    }
}
